home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / Browser / HTML Kurse / selfhtml / zjtext.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-10-14  |  4.4 KB  |  183 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9.  
  10. public class zjtext extends Applet implements Runnable {
  11.    static final int MAXCLORS = 10;
  12.    // $FF: renamed from: s java.lang.String
  13.    String field_0;
  14.    Thread jitterThread;
  15.    boolean threadSuspended = false;
  16.    int fontHeight;
  17.    Color textColor;
  18.    Color bgColor;
  19.    int speed = 200;
  20.    // $FF: renamed from: fm java.awt.FontMetrics
  21.    FontMetrics field_1;
  22.    int baseline;
  23.    Image offScrImage;
  24.    Graphics offScrGC;
  25.    boolean normal = false;
  26.    Font font;
  27.    Color[] randomColors = new Color[10];
  28.    boolean randomColor = false;
  29.  
  30.    public void init() {
  31.       Graphics var2 = ((Component)this).getGraphics();
  32.       this.fontHeight = ((Component)this).size().height - 10;
  33.       this.offScrImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  34.       this.offScrGC = this.offScrImage.getGraphics();
  35.       this.field_0 = ((Applet)this).getParameter("text");
  36.       if (this.field_0 == null) {
  37.          this.field_0 = "Java Power!";
  38.       }
  39.  
  40.       int var3 = ((Component)this).size().width - (this.field_0.length() + 1) * 5 - 10;
  41.  
  42.       do {
  43.          var2.setFont(new Font("TimesRoman", 1, this.fontHeight));
  44.          this.field_1 = var2.getFontMetrics();
  45.          if (this.field_1.stringWidth(this.field_0) > var3) {
  46.             --this.fontHeight;
  47.          }
  48.       } while(this.field_1.stringWidth(this.field_0) > var3);
  49.  
  50.       this.baseline = ((Component)this).size().height - this.field_1.getMaxDescent();
  51.       this.font = new Font("TimesRoman", 1, this.fontHeight);
  52.       String var1;
  53.       if ((var1 = ((Applet)this).getParameter("TEXTCOLOR")) == null) {
  54.          this.textColor = Color.black;
  55.       } else {
  56.          this.textColor = this.parseColorString(var1);
  57.       }
  58.  
  59.       if ((var1 = ((Applet)this).getParameter("BGCOLOR")) == null) {
  60.          this.bgColor = Color.lightGray;
  61.       } else {
  62.          this.bgColor = this.parseColorString(var1);
  63.       }
  64.  
  65.       ((Component)this).setBackground(this.bgColor);
  66.       if ((var1 = ((Applet)this).getParameter("SPEED")) != null) {
  67.          this.speed = Integer.valueOf(var1);
  68.       }
  69.  
  70.       if (this.speed == 0) {
  71.          this.speed = 200;
  72.       }
  73.  
  74.       if ((var1 = ((Applet)this).getParameter("RANDOMCOLOR")) != null) {
  75.          this.randomColor = Integer.valueOf(var1) != 0;
  76.       }
  77.  
  78.       this.randomColors[0] = Color.magenta;
  79.       this.randomColors[1] = Color.orange;
  80.       this.randomColors[2] = Color.red;
  81.       this.randomColors[3] = Color.white;
  82.       this.randomColors[4] = Color.yellow;
  83.       this.randomColors[5] = Color.blue;
  84.       this.randomColors[6] = Color.cyan;
  85.       this.randomColors[7] = Color.green;
  86.       this.randomColors[8] = Color.pink;
  87.       this.randomColors[9] = Color.gray;
  88.       this.jitterThread = new Thread(this);
  89.    }
  90.  
  91.    public void start() {
  92.       if (this.jitterThread != null) {
  93.          this.jitterThread.start();
  94.       }
  95.  
  96.    }
  97.  
  98.    public void stop() {
  99.       if (this.jitterThread != null) {
  100.          this.jitterThread.stop();
  101.       }
  102.  
  103.       this.jitterThread = null;
  104.    }
  105.  
  106.    public void run() {
  107.       for(; this.jitterThread != null; ((Component)this).repaint()) {
  108.          try {
  109.             Thread.sleep(200L);
  110.          } catch (InterruptedException var1) {
  111.          }
  112.       }
  113.  
  114.       System.exit(0);
  115.    }
  116.  
  117.    public boolean mouseDown(Event var1, int var2, int var3) {
  118.       if (this.threadSuspended) {
  119.          this.jitterThread.resume();
  120.          this.normal = false;
  121.       } else {
  122.          this.normal = true;
  123.          ((Component)this).repaint();
  124.          this.jitterThread.suspend();
  125.       }
  126.  
  127.       this.threadSuspended = !this.threadSuspended;
  128.       return true;
  129.    }
  130.  
  131.    public void paint(Graphics var1) {
  132.       if (this.normal) {
  133.          var1.setColor(this.bgColor);
  134.          var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  135.          var1.setColor(this.textColor);
  136.          var1.setFont(this.font);
  137.          var1.drawString(this.field_0, (((Component)this).size().width - this.field_1.stringWidth(this.field_0)) / 2, this.baseline);
  138.       }
  139.  
  140.    }
  141.  
  142.    public void update(Graphics var1) {
  143.       this.offScrGC.setColor(this.bgColor);
  144.       this.offScrGC.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  145.       this.offScrGC.setColor(this.textColor);
  146.       this.offScrGC.setFont(this.font);
  147.       if (!this.normal) {
  148.          int var3 = 0;
  149.  
  150.          for(int var4 = 0; var4 < this.field_0.length(); ++var4) {
  151.             if (this.randomColor) {
  152.                Color var2;
  153.                while(this.bgColor == (var2 = this.randomColors[Math.min(9, (int)(Math.random() * (double)10.0F))])) {
  154.                }
  155.  
  156.                this.offScrGC.setColor(var2);
  157.             }
  158.  
  159.             var3 += (int)(Math.random() * (double)10.0F);
  160.             int var5 = this.baseline - (int)(Math.random() * (double)10.0F);
  161.             String var6 = this.field_0.substring(var4, var4 + 1);
  162.             this.offScrGC.drawString(var6, var3, var5);
  163.             var3 += this.field_1.stringWidth(var6);
  164.          }
  165.       } else {
  166.          this.offScrGC.drawString(this.field_0, (((Component)this).size().width - this.field_1.stringWidth(this.field_0)) / 2, this.baseline);
  167.       }
  168.  
  169.       var1.drawImage(this.offScrImage, 0, 0, this);
  170.    }
  171.  
  172.    private Color parseColorString(String var1) {
  173.       if (var1.length() == 6) {
  174.          int var2 = Integer.valueOf(var1.substring(0, 2), 16);
  175.          int var3 = Integer.valueOf(var1.substring(2, 4), 16);
  176.          int var4 = Integer.valueOf(var1.substring(4, 6), 16);
  177.          return new Color(var2, var3, var4);
  178.       } else {
  179.          return Color.lightGray;
  180.       }
  181.    }
  182. }
  183.